package netWork;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

public class UdpDictServer extends UdpEchoServer{
    private HashMap<String,String> dict = new HashMap<>();//存储词库

    public UdpDictServer(int port) throws SocketException {
        super(port);

        dict.put("小猫", "cat");
        dict.put("小狗", "dog");
        dict.put("小兔子", "rabbit");
        dict.put("小鸭子", "duck");
    }

    public String process(String request){
      return  dict.getOrDefault(request,"未找到该词条");//存在request对应的value就返回value，否则返回defaultValue
    };

    public static void main(String[] args) throws IOException {
        UdpDictServer server = new UdpDictServer(9090);
        server.start();
    }
}
